
package labb4;

import java.util.ArrayList;
import java.util.List;

public class Composite extends Component{
    private String names;
    private double totWeight;
    
    private List<Component> Children = new ArrayList<>(); 
    private ArrayList<Component> AllChildren = new ArrayList<>(); 
    private Component child;
    
    
    Composite(String name, double weight){
        super(name, weight);  
    }
    void add(Component c){
        Children.add(c);
    }
    void remove(Component c){
        Children.remove(c);
    }
    public List<Component> getChildren(){
        return Children;           
        }
        
    //public ArrayList<Component> getChildren(Component c){
        //for (int i = 0; i < Children.size(); i++){
            //child = Children.get(i);
            //AllChildren.add(child);
            //getChildren(child);
        //}
        //return AllChildren;
    //}
    
    @Override
    public String toString(){
        names = name;
        for (Component child : Children){
            String cname = child.toString();
        names = (names+"\n"+cname);
        }
        return names;
    }
       
   public double getWeight(){
       totWeight = weight;
       for (Component child : Children){
           totWeight = totWeight + child.getWeight();
       }
   return totWeight;
   }
}

